﻿@{;
    ViewBag.Title = "列表页面";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>;
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设布局;
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $('#gridTable').setGridHeight($(window).height() - 136.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            autowidth: true,
            height: $(window).height() - 136.5,
            url: "../../CustomerManage/TBOrder/GetPageListJson",
            datatype: "json",
            colModel: [
                { label: '主键', name: 'Id', index: 'Id', width: 0, align: 'left',sortable: true ,hidden: true },
                { label: '订单编号', name: 'OrderId', index: 'OrderId', width: 200, align: 'center',sortable: true  },
                { label: '会员编号', name: 'CustomerId', index: 'CustomerId', width: 200, align: 'center',sortable: true  },
                {
                    label: '订单状态', name: 'Status', index: 'Status', width: 100, align: 'center',sortable: true ,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == "0") {
                            return "待审核";
                        }else if (cellvalue=="1") {
                            return "审核通过";
                        } else {
                            return "审核失败";
                        }
                    }
                },
                { label: '创建时间', name: 'CreateDate', index: 'CreateDate', width: 100, align: 'left',sortable: true  },
                { label: '创建人', name: 'CreateUserName', index: 'CreateUserName', width: 120, align: 'left',sortable: true  },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $('#' + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $('#' + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                CustomerId: $("#txt_Keyword").val(),
                OrderId: $("#txt_Keyword").val()
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: 'Form',
            title: '添加订单',
            url: '/CustomerManage/TBOrder/Form',
            width: '500px',
            height: '350px',
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $('#gridTable').jqGridRowValue('Id');
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: 'Form',
                title: '审核订单',
                url: '/CustomerManage/TBOrder/Form?keyValue=' + keyValue,
                width: '500px',
                height: '350px',
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $('#gridTable').jqGridRowValue('Id');
        if (keyValue) {
            $.RemoveForm({
                url: '../../CustomerManage/TBOrder/RemoveForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $('#gridTable').trigger('reloadGrid');
                }
            })
        } else {
            dialogMsg('请选择需要删除的订单记录！', 0);
        }
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>查询</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload()"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;审核</a>
            <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
    </div>
</div>
<div class="gridPanel">
    <table id="gridTable"></table>
    <div id="gridPager"></div>
</div>
